#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main.h"
#include "ModuleB/class.h"
#include "ModuleA/student.h"

int main() {
    struct Student students[100];
    struct Course courses[100];
    int num_students = 0;
    int num_courses = 0;
    char choice;

    loadCoursesFromFile(courses, &num_courses);
    loadStudentsFromFile(students, &num_students, courses, num_courses);

    while (1) {
        printf("学生选课系统管理功能:\n");
        printf("1. 新增学生信息\n");
        printf("2. 修改学生信息\n");
        printf("3. 删除学生信息\n");
        printf("4. 查看学生详细信息\n");
        printf("5. 新增课程\n");
        printf("6. 修改课程信息\n");
        printf("7. 删除课程\n");
        printf("8. 查看课程详细信息\n");
        printf("9. 退出\n");
        printf("请选择操作: ");
        scanf(" %c", &choice);

        switch (choice) {
            case '1':
                addStudent(students, &num_students, courses, &num_courses);
                break;
            case '2':
                printf("请输入要修改的学生学号: ");
                int student_id;
                scanf("%d", &student_id);
                modifyStudent(students, num_students, student_id, courses, num_courses);
                break;
            case '3':
                printf("请输入要删除的学生学号: ");
                int delete_student_id;
                scanf("%d", &delete_student_id);
                deleteStudent(students, &num_students, delete_student_id, courses, &num_courses);
                break;
            case '4':
                printf("请输入要查看的学生学号: ");
                int view_student_id;
                scanf("%d", &view_student_id);
                viewStudentDetails(students, num_students, view_student_id);
                break;
            case '5':
                addCourse(courses, &num_courses);
                break;
            case '6':
                printf("请输入要修改的课程编号: ");
                int course_code;
                scanf("%d", &course_code);
                modifyCourse(courses, num_courses, course_code);
                break;
            case '7':
                printf("请输入要删除的课程编号: ");
                int delete_course_code;
                scanf("%d", &delete_course_code);
                deleteCourse(courses, &num_courses, delete_course_code);
                break;
            case '8':
                printf("请输入要查看的课程编号: ");
                int view_course_code;
                scanf("%d", &view_course_code);
                viewCourseDetails(courses, num_courses, view_course_code);
                break;
            case '9':
                saveStudentsToFile(students, num_students);
                saveCoursesToFile(courses, num_courses);
                printf("已保存学生和课程信息到文件。\n");
                return 0;
            default:
                printf("无效的选项，请重新选择。\n");
                break;
        }
    }
}
